package com.gnerv.battle.boot.project.guard.controller;

import com.gnerv.battle.boot.common.base.model.RestResult;
import com.gnerv.battle.boot.project.guard.business.MonitorDatasourceBusiness;
import com.gnerv.battle.boot.project.guard.model.dto.MonitorDatasourceCreateDTO;
import com.gnerv.battle.boot.project.guard.model.dto.MonitorDatasourceDTO;
import com.gnerv.battle.boot.project.guard.model.dto.MonitorDatasourceUpdateDTO;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Gnerv LiGen
 */
@RestController
@AllArgsConstructor
@RequestMapping(value = "api/monitor/datasource")
public class MonitorDatasourceController {

    private final MonitorDatasourceBusiness monitorDatasourceBusiness;

    @PostMapping(value = "")
    public RestResult<Void> create(@RequestBody MonitorDatasourceCreateDTO monitorDatasourceCreateDTO) {
        return monitorDatasourceBusiness.create(monitorDatasourceCreateDTO);
    }

    @DeleteMapping(value = "")
    public RestResult<Void> deleteByUkId(@RequestParam(value = "ukId") String ukId) {
        return monitorDatasourceBusiness.deleteByUkId(ukId);
    }

    @PutMapping(value = "")
    public RestResult<Void> updateByUkId(@RequestBody MonitorDatasourceUpdateDTO monitorDatasourceUpdateDTO) {
        return monitorDatasourceBusiness.updateByUkId(monitorDatasourceUpdateDTO);
    }

    @GetMapping(value = "")
    public RestResult<MonitorDatasourceDTO> selectByUkId(@RequestParam(value = "ukId") String ukId) {
        return monitorDatasourceBusiness.selectByUkId(ukId);
    }

    @GetMapping(value = "list")
    public RestResult<List<MonitorDatasourceDTO>> listByName(@RequestParam(required = false, value = "name") String name,
                                                       @RequestParam(required = false, value = "page") Integer page,
                                                       @RequestParam(required = false, value = "size") Integer size) {
        return monitorDatasourceBusiness.listByName(name, page, size);
    }


}
